package com.delete.service.impl;

import com.delete.service.DeleteService;
import com.feign.util.FileUtil;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
public class DeleteServiceImpl implements DeleteService {
    /**
     * 批量删除文件
     * @param list 文件路径 英文,分割
     */
    @Override
    public void deleteFilePaths(List<String> list) {
        List<File> collect = list.stream().map(item -> {
            File file = new File(item);
            return file.exists() ? file : null;
        }).filter(Objects::nonNull).collect(Collectors.toList());

        FileUtil.deleteFiles(collect);
    }
}
